﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HWInfo.Models
{
    public class MemoryStatus
    {
        /// <summary>
        /// 内存大小
        /// </summary>
        public double Total { get; internal set; }

        /// <summary>
        /// 可用内存
        /// </summary>
        public double Available { get; internal set; }

        public double Free { get; internal set; }

        public double Buffers { get; internal set; }

        public double Cached { get; internal set; }

        /// <summary>
        /// 交换文件大小
        /// </summary>
        public double SwapTotal { get; internal set; }

        /// <summary>
        /// 可用交换文件大小
        /// </summary>
        public double SwapAvailable { get; internal set; }

        public double Usage 
        {
            get
            {
                //var ava = (float)(Available + SwapAvailable);
                //var total = (float)(Total + SwapTotal);
                //return 100 - 100 * (Available / Total);

                return Math.Round(((Total - (Free + Buffers + Cached)) / Total) * 100, 2);
            }
        }

        public override string ToString()
        {
            return
                "Total: " + Math.Round(Total, 2) + Environment.NewLine +
                "Available: " + Math.Round(Available, 2) + Environment.NewLine +
                "Buffers: " + Math.Round(Buffers, 2) + Environment.NewLine +
                "Cached: " + Math.Round(Cached, 2) + Environment.NewLine +
                "SwapTotal: " + Math.Round(SwapTotal, 2) + Environment.NewLine +
                "SwapAvailable: " + Math.Round(SwapAvailable, 2) + Environment.NewLine +
                "Usage: " + Usage + Environment.NewLine;
        }
    }
}
